<?


class Dataconnection{
    var $error;
    var $conf;
    function DataConnection() {
        $this->conf=new Dataconfig();
    }
    function executeSQL($SQLCommand){
        try{
            $dbURL  = $this->conf->host;
            $dbName = $this->conf->database;
            $dbUsr  = $this->conf->username;
            $dbPwd  = $this->conf->password;
            $_MySQL= new mysqli( $dbURL, $dbUsr, $dbPwd, $dbName );
            $_MySQL -> query( "SET NAMES 'UTF8'" );
            $_MySQL -> query( "SET SQL_SAFE_UPDATES=0" );
            $result =  $_MySQL->query($SQLCommand);
	    //if(isset($result->num_rows)?$result->num_rows:false) return $result;
            if ($_MySQL->errno!=0){
	            $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
	            $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
	            $errmsg.= new Exception($_MySQL->error." - <span style='color:#FFAC30;'>".$SQLCommand."</span>", "1");
	            $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
	            $this->error=$errmsg;
                    $_MySQL->close();
	            return null;
	        }
        } catch (Exception $exc) {
            
            $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
            $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
            $errmsg.= $exc->getTraceAsString();
            $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
            $this->error=$errmsg;
            $_MySQL->close();
            return null;
        }

        $_MySQL->close();
        return $result;
        return null;
    }
    function executeNoneSQL($SQLCommand){
        try {
            $dbURL  = $this->conf->host;
            $dbName = $this->conf->database;
            $dbUsr  = $this->conf->username;
            $dbPwd  = $this->conf->password;
            $_MySQL= new mysqli( $dbURL, $dbUsr, $dbPwd, $dbName );
            $_MySQL -> query( "SET NAMES 'UTF8'" );
            $_MySQL -> query( "SET SQL_SAFE_UPDATES=0" );
            $result =  $_MySQL->query ($SQLCommand);
            $affected_rows=$_MySQL->affected_rows;//mysql_affected_rows();
            if ($_MySQL->errno!=0){
                $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
                $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
                $errmsg.= new Exception($_MySQL->error." - <span style='color:#FFAC30;'>".$SQLCommand."</span>", "1");
                $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
                $this->error=$errmsg;
                $_MySQL->close();
                return 0;
            }
        } catch (Exception $exc) {
            $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
            $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
            $errmsg.= $exc->getTraceAsString();
            $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
            $this->error=$errmsg;
            $_MySQL->close();
            return 0;
            
        }
        $_MySQL->close();
        return $affected_rows;
    }
}
?>